package cn.mumzone.pos.model.source;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.net.response.PageListResponse;
import cn.mumzone.basic.net.source.AbsRepository;
import cn.mumzone.basic.util.RxUtil;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.api.ApiRequest;
import cn.mumzone.pos.model.BillDetailEntity;
import cn.mumzone.pos.model.BillInfoListBean;
import cn.mumzone.pos.model.RechargeDetailEntity;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Response;
import retrofit2.http.Query;

/**
 * Created By Dlx
 * on 2019/6/26
 */
public class BillsRepository extends AbsRepository {
    public void getBillDatas(String dateTime, String keyword, String type, String pageNum, String pageSize, ApiCallBack<PageListResponse<BillInfoListBean>> callBack) {

        String allBills = AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isAllBills() ? "1" : "";
        ApiRequest.getBillService()
                .getAccountPageList(dateTime, allBills, keyword, type, pageNum, pageSize)
                .compose(RxUtil.<Response<BaseResponse<PageListResponse<BillInfoListBean>>>>applySchedulers())
                .subscribe(callBack);
    }

    public void getBillDetail(String saleId, String orderType, ApiCallBack<BillDetailEntity> billDetailCallback) {
        ApiRequest.getBillService()
                .getBillDetail(saleId, orderType)
                .compose(RxUtil.<Response<BaseResponse<BillDetailEntity>>>applySchedulers())
                .subscribe(billDetailCallback);
    }


    public void getRechargeBillDetail(String saleId, String memberId, ApiCallBack<RechargeDetailEntity> billDetailCallback) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("saleId", saleId);
        jsonObject.put("memberCompanyId", memberId);
        jsonObject.put("storeType", String.valueOf(AppConstants.TEMP_SHOP_STORE_TYPE));
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonObject.toString());
        ApiRequest.getBillService()
                .getRechargeBillDetail(body)
                .compose(RxUtil.<Response<BaseResponse<RechargeDetailEntity>>>applySchedulers())
                .subscribe(billDetailCallback);
    }


}
